<?php
class front_adminController extends accessController{
    public static function _right(){
        return array(
            array('前台会员管理',1),
            array('会员账号添加','add,add_'),
            array('会员账号列表','li'),
            array('会员账号编辑','mod,mod_'),
            array('会员账号删除','del'),
            array('批量操作','bit_op'),
        );
    }
    public function index(){
        
    }
    public function add(){
		$group_service=load_service('front_group');
		$group_arr=$group_service->with_option();
		$group_data=$group_service->make_option_array($group_arr);
		
        include($this->viewer_dir.'front_admin/add.php');
    }
    public function add_(){
        $admin=load_service('front_admin');
		$group=load_service('front_group');
		
		
        $r=$admin->add_($_POST);
        if($r[0]){
            alert('会员添加成功！');
            jump('front_admin','add');
        }else{
            alert('会员添加失败！'.$r[1]);
            back();
        }
    }
    public function mod(){
        $admin=load_service('front_admin');
        $id=intval($_GET['id']);
        
        $data=$admin->mod($_GET['id']);
        if($data){
			$group_service=load_service('front_group');
			$group_arr=$group_service->with_option();
			$group_data=$group_service->make_option_array($group_arr);
			
            include($this->viewer_dir.'front_admin/mod.php');
        }
    }
    public function mod_(){
        $admin=load_service('front_admin');
		$group=load_service('front_group');
		
        $id=intval($_GET['id']);
        
		
        $r=$admin->mod_($_POST,$id);
        if($r[0]){
            alert('会员编辑成功！');
            reload();
        }else{
            alert('会员编辑失败！'.$r[1]);
            back();
        }
    }
    public function del(){
        $admin=load_service('front_admin');
        $id=intval($_GET['id']);
        
       
        if($admin->del($_GET['id'])){
            alert('删除成功！');
            jump('front_admin','li');
        }else{
            alert('删除失败！');
            back();
        }
    }
    public function li(){
		
		$tag_data=array('-1'=>'--请选择--','0'=>'屏蔽','1'=>'正常');
		
		
		$condition=array();
		$extra='';
		$extra_data=array();
		
		isset($_GET['tag']) or $_GET['tag']=-1;
		$tag=intval($_GET['tag']);//
		if($tag>-1){
			$condition['tag']=$tag;
			$extra.=" and `tag`=:tag";
			$extra_data['tag']=$tag;
		}
		
		$reg_time_1=$_GET['reg_time_1'];//
		if($reg_time_1){
			$condition['reg_time_1']=$reg_time_1;
			$tmp=strtotime($reg_time_1);
			$extra.=" and `reg_time`>=:rt_1";
			$extra_data['rt_1']=$tmp;
		}
		$reg_time_2=$_GET['reg_time_2'];//
		if($reg_time_2){
			$condition['reg_time_2']=$reg_time_2;
			$tmp=strtotime($reg_time_2);
			$extra.=" and `reg_time`<=:rt_2";
			$extra_data['rt_2']=$tmp;
		}
		
		$id=intval($_GET['id']);//
		if($id){
			$condition['id']=$id;
			$extra.=" and `id`=:id";
			$extra_data['id']=$id;
		}
		
		$group_id=intval($_GET['group_id']);//
		if($group_id){
			$condition['group_id']=$group_id;
			$extra.=" and `group_id`=:group_id";
			$extra_data['group_id']=$group_id;
		}
		
		$user_name=trim($_GET['user_name']);//
		if($user_name){
			$condition['user_name']=$user_name;
			$extra.=" and `user_name` like :user_name";
			$extra_data['user_name']="%{$user_name}%";
		}
		$email=trim($_GET['email']);//
		if($email){
			$condition['email']=$email;
			$extra.=" and `email` = :email";
			$extra_data['email']=$email;
		}
		
		
		$group_service=load_service('front_group');
		$group_arr=$group_service->with_option();
		$group_data=$group_service->make_option_array($group_arr);
		
        $admin=load_service('front_admin');
        $return=$admin->li($condition,$extra,$extra_data);
        include($this->viewer_dir.'front_admin/list.php');
    }
	//批量操作 文章列表页调用
	public function bit_op(){
		if(empty($_POST)) exit;
		$k=$_GET['k'];
		$items=$_POST['items'];
		if(empty($items)) exit;
		$admin=load_service('front_admin');
		switch($k){
			case 'delete':
			$admin->delete($items);
			break;
			case 'update_status'://已做
			$admin->update_status($items,$_POST['tag']);
			break;
			case 'export':
			
			break;
			default:
			exit('k error!');
			break;
		}
		alert('操作成功！');
		back();
	}
}